package DSENS;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.ArrayList;

/**
 *
 * @author filippo
 */
public class FloodingNode extends Node {

    Log l = new Log();

    @Override
    public void receiveEvent(Event e) {
        try {
            l.printEvent(e, "receiving event");
        } catch (LogException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void manageEvent(Event e) {
       if((e.getMessage().getTimetolive()>0) && (neighborood.size()>0)){
            Message msg = new Message(e.getMessage().getTimetolive()-1);
            
            for(int i = 0; i < neighborood.size(); i++) {
                Event ev = new Event(this.ID, this.neighborood.get(i).getId(), e.geteventType(), this.neighborood.get(i).getLinkSize(), msg);
                GlobalInfo.TIMELINE.addEvent(ev.getDistance(), ev);
                try {
                    l.printEvent(ev, "sending event");
                } catch (LogException ex) {
                    ex.printStackTrace();
                }
            }
        }
        else l.printlnLog("Nothing to do...");
    }


    public FloodingNode() {
        super();
    }

    public FloodingNode(ArrayList<Neighbour> neighborood) {
        super(neighborood);
    }
}
